package com.yyaccp.appinfo.service;

import com.yyaccp.appinfo.domain.AppInfo;
import com.yyaccp.appinfo.mapper.AppInfoMapper;
import com.yyaccp.appinfo.util.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("appInfoService")
public class AppInfoService {
    @Resource
    private AppInfoMapper appInfoMapper;

    public void search(AppInfo appInfo, Page pageObj){
        int totalCount = appInfoMapper.getCount(appInfo);
        pageObj.setTotalCount(totalCount);
        int pageIndex = (pageObj.getPageindex()-1)*pageObj.getPageSize();
        if(totalCount > 0){
            if(pageObj.getPageindex() > pageObj.getTotalCountPage()){
                pageObj.setPageindex(pageObj.getTotalCountPage());
            }
            List<AppInfo> dataList = appInfoMapper.selectAll(appInfo,pageIndex,pageObj.getPageSize());
            pageObj.setDatalist(dataList);
        }else{
            pageObj.setPageindex(0);
            pageObj.setDatalist(new ArrayList<AppInfo>());
        }
    }
    public int upDataByid(AppInfo appinfo){
        return appInfoMapper.upDataByid(appinfo);
    }
}
